var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    errshow: !1, //错误提示
    subboor: !0, //按钮
    pingfen: 0, //评分,
    state: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this,
      keywords = options.keywords,
      zid = options.zid,
      j_id = options.j_id,
      orders = options.orders;
    app.util.request({
      'url': 'entry/wxapp/Hzbingli.url',
      success: function(res) {
        console.log(res)
        that.setData({
          url: res.data
        })
      },
    })
    app.util.request({
      url: "entry/wxapp/Zhuanjia.docinfo",
      data: {
        zid: zid
      },
      success(res) {
        console.log(res)
        that.setData({
          xiangqing: res.data.data
        })
      }
    })
    that.setData({
      keywords: keywords,
      zid: zid,
      j_id: j_id,
      orders: orders,
    })
  },
  //减星
  jianxing(e) {
    var t = this,
      i = parseInt(e.currentTarget.dataset.dex);
    t.setData({
      pingfen: i
    })
  },
  //加星
  jiaxing(e) {
    var t = this,
      x = t.data.pingfen,
      i = e.currentTarget.dataset.dex;
    x += i;
    t.setData({
      pingfen: ++x
    })
  },
  //表单提交
  wenzhenform(e) {
    console.log(e)
    var t = this,
      pf = t.data.pingfen,
      keywords = t.data.keywords,
      zid = t.data.zid,
      j_id = t.data.j_id,
      orders = t.data.orders,
      val = e.detail.value;
    if (pf == 0) {
      t.setData({
        errtext: "请您评分！",
        errshow: !0
      })
      setTimeout(function() {
        t.setData({
          errshow: !1
        })
      }, 1000)
    } else if (val.bingqing == "") {
      t.setData({
        errtext: "请您输入文字评价！",
        errshow: !0
      })
      setTimeout(function() {
        t.setData({
          errshow: !1
        })
      }, 1000)
    } else {
      var state = 0
      t.setData({
        state: state
      })
      val.pf = pf;
      var bingqing = val.bingqing
      var uniacid = app.siteInfo.uniacid;
      console.log(keywords)
      app.util.request({
        url: t.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Pinglun&m=hyb_yl',
        data: {
          starsnum: pf,
          content: bingqing,
          openid: wx.getStorageSync('openid'),
          orders: orders,
          zid: zid,
          keywords: keywords,
          j_id: j_id,
        },
        success(res) {
          console.log(res);
          wx.showToast({
            title: '评价成功',
            icon: "loading",
            duration: 1e3,
            success: function() {
              var pages = getCurrentPages();
              var prevPage = pages[pages.length - 2];
              prevPage.setData({
                pingjia: 1
              })
              setTimeout(function() {
                wx.navigateBack({
                  detail: 1
                })
              }, 1000)
            }
          })
        }
      })

    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {
    var that = this
    var wanc = that.data.wanc
    console.log(wanc)
    if (wanc == 1) {
      //判断页面栈里面的页面数是否大于2
      if (getCurrentPages().length > 2) {
        //获取页面栈
        let pages = getCurrentPages()
        //给上一个页面设置状态
        let curPage = pages[pages.length - 2];
        let data = curPage.data;
        curPage.setData({
          'isBack': true
        });
      }
    }
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

})